<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserBalanceTransferRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('user_balance_transfer_records', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->comment('用户编号');
            $table->string('order_sn')->comment('订单编号');
            $table->string('type')->comment('变动类型 consume 消费；charge 充值；refund 退款；');
            $table->float('money')->comment('变动金额');
            $table->float('balance')->comment('变动后的账户余额');
            $table->timestamps();

            $table->index('order_sn');
            $table->index('type');
            $table->foreign('user_id')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('user_balance_transfer_records');
    }
}
